/*
 * Licensed Materials - Property of tenxcloud.com
 * (C) Copyright 2018 TenxCloud. All Rights Reserved.
 * 2018-06-13  @author lizhen
 */

package server

import (
	"github.com/gin-contrib/cors"
	"github.com/gin-gonic/gin"
	"math/rand"
	"modules.tenxcloud.com/common/composite"
	"runtime"
	"time"
)

var (
	Application = gin.Default()
)

func init() {
	runtime.GOMAXPROCS(runtime.NumCPU())
	rand.Seed(time.Now().UTC().UnixNano())
	config := composite.Configuration
	gin.SetMode(config.RunMode())
	corsConfig := cors.DefaultConfig()
	corsConfig.AllowAllOrigins = true
	corsConfig.AllowHeaders = config.CORSAllowHeaders()
	corsConfig.AllowMethods = config.CORSAllowMethods()
	Application.Use(cors.New(corsConfig))
	composite.Pool.Start()
}
